home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / lib / tclX-6.4 / help / intro / brackets < prev    next >
Encoding:
Text File  |  1992-12-17  |  1.6 KB  |  42 lines

  1.      COMMAND SUBSTITUTION WITH BRACKETS
  2.           If an open bracket occurs in a  field  of  a  command,  then
  3.           command  substitution  occurs (except for fields enclosed in
  4.           braces).  All of the text up to the matching  close  bracket
  5.           is  treated as a Tcl command and executed immediately.  Then
  6.           the result of that command is substituted for the  bracketed
  7.           text.  For example, consider the command
  8.  
  9.                set a [set b]
  10.  
  11.           When the set command has only a single argument, it  is  the
  12.           name  of  a  variable  and  set returns the contents of that
  13.           variable.  In this case, if variable b has  the  value  foo,
  14.           then the command above is equivalent to the command
  15.  
  16.                set a foo
  17.           Brackets can be used in more complex ways.  For example,  if
  18.           the  variable b has the value foo and the variable c has the
  19.           value gorp, then the command
  20.  
  21.                set a xyz[set b].[set c]
  22.  
  23.           is equivalent to the command
  24.  
  25.                set a xyzfoo.gorp
  26.  
  27.           A bracketed command may contain multiple commands  separated
  28.           by  newlines  or  semi-colons in the usual fashion.  In this
  29.           case the value of the last command is used for substitution.
  30.           For example, the command
  31.  
  32.                set a x[set b 22
  33.                expr $b+2]x
  34.  
  35.           is equivalent to the command
  36.  
  37.                set a x24x
  38.  
  39.           If a field is enclosed in braces then the brackets  and  the
  40.           characters  between them are not interpreted specially; they
  41.           are passed through to the argument verbatim.
  42.